/**
 * 
 */
package com.guo.hui.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.Map;

/**
 * @className FileDate
 * @author zhengguohui
 * @description
 * @date 2018年7月20日
 */
public class FileDate {

	public static void main(String[] args) throws MalformedURLException {
		URL url = new URL("http://47.104.139.62:9000/tt.txt");
		StringBuilder localStrBulider = new StringBuilder();
		InputStream input;
		try {
			input = url.openStream();
			InputStreamReader inputStreamReader = new InputStreamReader(input, "utf-8");
			BufferedReader bufferReader = new BufferedReader(inputStreamReader);
			String lineStr = null;
			try {
				while ((lineStr = bufferReader.readLine()) != null) {
					localStrBulider.append(lineStr);
				}
				bufferReader.close();
				inputStreamReader.close();
			} catch (IOException e) {
				bufferReader.close();
				inputStreamReader.close();
			}
		} catch (IOException e) {

		}
		System.out.println(localStrBulider.toString());
		// File file = new File("");
		// if (file.exists()) {
		// LinkedList<File> list = new LinkedList<File>();
		// File[] files = file.listFiles();
		// for (File file2 : files) {
		// readFile(file2);
		// }
		// } else {
		// System.out.println("文件不存在!");
		// }
		// System.out.println("文件夹共有:");
	}

	// 获取文件数据
	public static void readFile(String path) {
//		File file = new File(path);
//		if (file.exists()) {
//			File[] files = file.listFiles();
//			for (File file2 : files) {
//				readFile(file2);
//			}
//		}
		// String path = "D:/";
		File file = new File(path);
		StringBuilder localStrBulider = new StringBuilder();
		if (file.isFile() && file.exists()) {
			try {
				InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
				BufferedReader bufferReader = new BufferedReader(inputStreamReader);
				String lineStr = null;
				try {
					while ((lineStr = bufferReader.readLine()) != null) {
						localStrBulider.append(lineStr);
					}
					bufferReader.close();
					inputStreamReader.close();
				} catch (IOException e) {
					bufferReader.close();
					inputStreamReader.close();
				}
			} catch (IOException e) {
			}
		} else {
			System.out.println("文件不存在!");
		}
		System.out.println("文本数据:" + localStrBulider.toString());
	}

	// 获取文件数据
	public static void readUrlFileDetail() throws MalformedURLException {

		URL url = new URL("file:///D:/ads.txt");
		InputStream ism;
		try {
			StringBuilder localStrBulider = new StringBuilder();
			ism = url.openStream();
			InputStreamReader inputStreamReader = new InputStreamReader(ism, "utf-8");
			BufferedReader bufferReader = new BufferedReader(inputStreamReader);
			String lineStr = null;
			try {
				while ((lineStr = bufferReader.readLine()) != null) {
					System.out.println("bufff" + lineStr);
					localStrBulider.append(lineStr);
				}
				System.out.println(localStrBulider.toString());
				bufferReader.close();
				inputStreamReader.close();
			} catch (IOException e) {
				e.printStackTrace();
				bufferReader.close();
				inputStreamReader.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		// readFile("D:/ads.txt");

	}

	// 获取文件数据
	public static void readUrlFile() {
		URL url = null;
		try {
			url = new URL("file:///D:/ads.txt");
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		InputStream ism;
		try {
			ism = url.openStream();
			byte[] bytes = new byte[1024];
			ism.read(bytes);
			String str = new String(bytes, "utf-8");
			System.err.println(str);
			while (ism.read(bytes) > -1) {
				System.err.println(str);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		// readFile("D:/ads.txt");

	}

}
